import java.util.Arrays;

public class Test2 {

    /*
     * 在数组中查询key是否存在，存在返回true，否则返回false
     * */
    public static boolean isExist(int[] list, int key) {
        for (int i = 0; i < list.length; i++) {
            if (list[i] == key) {
                return true;
            }
        }
        return false;
    }

    public static int[] bornRandom() {
        int[] list = new int[60];
        for (int i = 0; i < list.length; i++) {
            while (true) {// 生成一个之前没有生成过的随机数，并插入数组
                int random = ((int) (Math.random() * 100)) + 100;
//                boolean isExist = isExist(list, random);
                boolean isExist = Arrays.binarySearch(list, random) > 0;
                if (isExist == false) {
                    list[i] = random;
                    break;
                }
            }
        }
        return list;
    }


    public static void main(String[] args) {

        int[] list = bornRandom();
        for (int i = 0; i < list.length; i++) {
            System.out.printf("%d:%d\n", i + 1, list[i]);
            //list[i]+=1;// 可以修改数组
        }
        // foreach
        int i = 1;
        for (int item : list) {
            System.out.printf("%d:%d\n", i++, item);
            // 只能对数组进行读取操作
        }

    }

}
